package com.ky.home.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


import com.ky.common.vo.R;
import com.ky.home.entity.Article;

import com.ky.home.mapper.ArticleMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version 1.0
 * @Author 小胤
 * @Date 2024/6/17 14:22
 * @注释
 */
@RestController
@RequestMapping("/home")
public class SearchController {
    @Autowired
    private ArticleMapper articleMapper;

    @RequestMapping("/search/all")
    public R search() {
        // QueryWrapper<Article> articleQueryWrapper = new QueryWrapper<>();
        // articleQueryWrapper.like("title", value).or().like("content", value);
        // articleQueryWrapper.in("category", "备考经验", "案例分析", "快题","建筑史","技术");
        List<Article> articles = articleMapper.selectList(null);
        if (articles.size()>0){
            return R.ok(articles);
        }
        return R.fail("查询失败");
    }
    @RequestMapping("/search/{value}")
    public R search(@PathVariable("value")String value) {

        QueryWrapper<Article> articleQueryWrapper = new QueryWrapper<>();
        articleQueryWrapper.like("title", value).or().like("content", value);
        articleQueryWrapper.in("category", "备考经验", "案例分析", "快题","建筑史","技术");
        List<Article> articles = articleMapper.selectList(articleQueryWrapper);
        if (articles.size()>0){
            return R.ok(articles);
        }
        return R.fail("查询失败");
    }
}
